$(document).ready(function() {
    searchAction.init();
});

var searchAction = (function() {
    
    function searchAction() {
        var user = $('#postUser').val(),
            dateFrom =  $('#tuNgay').val(),   
            dateTo =  $('#denNgay').val(),   
            nameDetail = $('#detail').val();
        
        
        $('.form-group').removeClass('has-error');
        $('.errorHandler').html('');
        
        
        $.post('/action/search', {
            user: user,
            dateFrom: dateFrom,
            dateTo: dateTo,
            nameDetail: nameDetail
        }, function(resp) {
            if (resp.err == 0) {
                
                //callback();
                //hideConfirm();
                //window.location.href = '/action/search';
            } else {
                $('.errorHandler').html('<small><small><strong class="text-danger">' + resp.msg + '</strong></small></small>').show();
            }
        }, 'json');
    }
    
    function initHanlder() {
        initWysiwyg();

        $('#searchAction').click(function() {
            $(this).find('i.fa').attr('class', 'fa fa-spinner fa-spin');
            searchAction();
            return false;
        });
    }
    
    
    return {
        init: function() {   
            //initHanlder();
            initDatePicker('#tuNgay');
            initDatePicker('#denNgay');
        }
    };
})();